<html>
<head>
</head>

<body>
<script type="text/javascript">
var socket ;

if(!window.WebSocket) {
	window.socket = window.MozWebSocket;
} 
if(window.WebSocket) {
	socket = new WebSocket("ws://localhost:8080/websocket")
	socket.onmessage = function(event) {
		var ta = document.getElementById('responseText');
		ta.value = '';
		ta.value = event.data;
	};
	socket.onopen = function(event) {
		var ta = document.getElementById('responseText');
		ta.value = 'websocket opened';
	};
	socket.onclose = function(event) {
		var ta = document.getElementById('responseText');
		ta.value = 'websocket closed';
	};
} else {
	var ta = document.getElementById('responseText');
	ta.value = 'websocket not supported';
}

function send() {
	var msg = document.getElementById('message').value;
	if(!window.WebSocket) {
		return;
	}
	if(socket.readyState == WebSocket.OPEN) {
		socket.send(msg);
	} else {
		alert('WebSocket连接失败');
	}
}
</script>


<input type="text" id="message" name="message" value="Netty" />
<input type="button" value="Send" onclick="send()" />

<h3>Response from Server</h3>
<textarea id="responseText" style="width: 500px;height: 200px;"></textarea>
</body>

</html>